/**
 * Created by WT-SUN on 2017/6/8.
 */

$(function () {
    var date = new Date();
    var year = date.getFullYear();
    $('#monTb').treegrid({
        striped: true,
        idField:'id',
        treeField:'name',
        fit: true,
        singleSelect: true,
        fitColumns: true,
        toolbar: '#toolbar',
        url: ROOT_PATH + '/occupationalHealth/monitor/selectAnalysis.shtml',
        queryParams:{
            yearAnnual:year
        },
        columns: [[
            {field: 'name', title: '单位', width: 100},
            {field: 'num1', title: '应测点次', width: 100},
            {field: 'num2', title: '实测点次', width: 100},
            {field: 'aa1', title: '监测率', width: 100,formatter: function (value, row, index) {
                var aValue=row.num1=='0'?'0.00':((row.num2*1)/(row.num1*1)*100).toFixed(2);
                return aValue+"%";
            }},
            {field: 'num3', title: '超标点次', width: 100},
            {field: 'aa2', title: '合格率', width: 100,formatter: function (value, row, index) {
                var aValue=row.num2=='0'?'0.00':((row.num2*1-row.num3*1)/(row.num2*1)*100).toFixed(2);
                return aValue+"%";
            }},
            {field: 'num4', title: '岗位值监测', width: 100},
            {field: 'num5', title: '超标岗位值', width: 100}
        ]]
    });
    /**
     * 高级查询
     */
    $('#btn_clear').on("click", function () {
        $('#queryForm1').form('reset');
        $('#queryForm2').form('reset');
        var date = new Date();
        var year = date.getFullYear();
        $("#yearAnnual").combobox('select', year);
    });

    queryYearthList("yearAnnual");

});
function queryYearthList(id){
    var date = new Date();
    var year = date.getFullYear();
    var yearthData = new Array();
    for(var i =0;i<6;i++){
        var y = {id:year-i,text:(year-i)+'年'};
        yearthData.push(y);
    }
    $('#'+id).combobox(
        {
            data:yearthData,
            valueField:'id',
            textField:'text',
            onLoadSuccess: function () { //加载完成后,设置选中第一项
                $(this).combobox('select', yearthData[0].id);
            }
        }
    );
}


/**
 * 重新加载表格
 */
function reLoadData() {
    $('#monTb').datagrid('clearSelections');
    var queryParams1 = $('#queryForm1').serializeJson();
    var queryParams2 = $('#queryForm2').serializeJson();
    var queryParams = $.extend(queryParams1,queryParams2);
    $('#monTb').treegrid('options').queryParams = queryParams;
    $("#monTb").treegrid('reload');
}
